package com.runda.partypolicy.app.page.fragment.home;


import android.os.Bundle;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.runda.partypolicy.R;
import com.runda.partypolicy.app.base.BaseFragment;
import com.runda.partypolicy.app.page.viewmodel.ViewModel_Main_Message;
import com.runda.partypolicy.app.repository.bean.ChatBean;
import com.runda.partypolicy.utils.recyclebase.CommonAdapter;
import com.runda.partypolicy.utils.recyclebase.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

/**
 * 主界面- 消息
 */


public class Fragment_Main_Message extends BaseFragment<ViewModel_Main_Message> {


    @BindView(R.id.commen_title_back)
    ImageView commenTitleBack;
    @BindView(R.id.commen_title_name)
    TextView commenTitleName;
    @BindView(R.id.commen_title_img)
    ImageView commenTitleImg;
    @BindView(R.id.commen_title_start)
    ImageView commenTitleStart;
    @BindView(R.id.commen_search_img)
    ImageView commenSearchImg;
    @BindView(R.id.recycle_first)
    RecyclerView recycleFirst;


    public Fragment_Main_Message() {
        // Required empty public constructor
    }

    public static Fragment_Main_Message newInstance() {

        Bundle args = new Bundle();

        Fragment_Main_Message fragment = new Fragment_Main_Message();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public int getLayout() {
        return R.layout.fragment_message;
    }

    @Override
    public ViewModel_Main_Message initViewModel() {
        return ViewModelProviders.of(this, getViewModelFactory()).get(ViewModel_Main_Message.class);
    }

    @Override
    public void initEvents() {
        commenTitleName.setText("消息");
        commenSearchImg.setVisibility(View.VISIBLE);
        initView();
    }

    @Override
    public void start() {
    }

    @Override
    public void initNotSignEvent() {

    }

    @Override
    public void initNoNetworkEvent() {

    }

    @Override
    public void initShowMessageEvent() {

    }

    @Override
    public void initTokenOverTimeEvent() {

    }

    @Override
    public void initShowOrDismissWaitingEvent() {

    }

    @Override
    public void initStateLayoutEvent() {

    }





    private void initView() {
        List<ChatBean> list = new ArrayList<ChatBean>();
        ChatBean chatBean = new ChatBean(R.drawable.msg_head1, "十大片区拆迁群", "民房1258户，约1288亩", "2019.04.04", "9");
        ChatBean chatBean2 = new ChatBean(R.drawable.icon_msg_db, "区委领导交办的任务", "你的报告已通过审批", "2019.04.04", "");
        ChatBean chatBean3 = new ChatBean(R.drawable.icon_msg_gw, "来自上级党委的公文", "来自上级党委的公文", "2019.04.04", "");
        ChatBean chatBean4 = new ChatBean(R.drawable.icon_msg_tz, "会议通知", "略", "2019.04.04", "");
        ChatBean chatBean5 = new ChatBean(R.drawable.msg_head5, "王先明", "下午2点，大会议室开会", "2019.04.04", "");


        list.add(chatBean);
        list.add(chatBean2);
        list.add(chatBean3);
        list.add(chatBean4);
        list.add(chatBean5);


        recycleFirst.setLayoutManager(new LinearLayoutManager(getActivity()));
        recycleFirst.setAdapter(new CommonAdapter(getContext(), R.layout.item_first_layout, list) {

            @Override
            protected void convert(ViewHolder holder, Object o, int position) {
                holder.setText(R.id.chat_name, list.get(position).getName());
                holder.setText(R.id.chat_current, list.get(position).getMsg());
                holder.setText(R.id.chat_time, list.get(position).getTime());
                holder.setImageResource(R.id.chat_img, list.get(position).getImgSrc());
                if (!TextUtils.isEmpty(list.get(position).getNum())) {
                    holder.setText(R.id.chat_num, list.get(position).getNum());
                } else {
                    holder.getView(R.id.chat_num).setVisibility(View.INVISIBLE);
                }
            }

        });
    }


}
